using JGSY.CMS.LowCode.Platform.Domain.Entities;

namespace JGSY.CMS.LowCode.Platform.Application.Interfaces
{
    /// <summary>
    /// 通知管理服务接口
    /// </summary>
    public interface INotificationService
    {
        // =============================
        // 通知发送
        // =============================

        /// <summary>
        /// 发送通知
        /// </summary>
        Task<NotificationRecord> SendNotificationAsync(string tenantId, string notificationType, string recipient, string subject, string content, Dictionary<string, object>? metadata = null);

        /// <summary>
        /// 使用模板发送通知
        /// </summary>
        Task<NotificationRecord> SendTemplateNotificationAsync(string tenantId, string templateCode, string recipient, Dictionary<string, object> variables, Dictionary<string, object>? metadata = null);

        /// <summary>
        /// 批量发送通知
        /// </summary>
        Task<List<NotificationRecord>> SendBatchNotificationAsync(string tenantId, string templateCode, List<string> recipients, Dictionary<string, object> variables);

        /// <summary>
        /// 计划发送通知
        /// </summary>
        Task<NotificationRecord> ScheduleNotificationAsync(string tenantId, string templateCode, string recipient, Dictionary<string, object> variables, DateTime scheduledAt);

        // =============================
        // 模板管理
        // =============================

        /// <summary>
        /// 创建通知模板
        /// </summary>
        Task<NotificationTemplate> CreateTemplateAsync(string tenantId, string name, string code, string notificationType, string subject, string content, Dictionary<string, object>? variables = null);

        /// <summary>
        /// 更新通知模板
        /// </summary>
        Task<NotificationTemplate?> UpdateTemplateAsync(long templateId, string? name = null, string? subject = null, string? content = null, Dictionary<string, object>? variables = null);

        /// <summary>
        /// 获取通知模板
        /// </summary>
        Task<NotificationTemplate?> GetTemplateAsync(string tenantId, string code);

        /// <summary>
        /// 获取模板列表
        /// </summary>
        Task<List<NotificationTemplate>> GetTemplatesAsync(string tenantId, string? notificationType = null, bool? isEnabled = null);

        /// <summary>
        /// 删除通知模板
        /// </summary>
        Task<bool> DeleteTemplateAsync(long templateId);

        // =============================
        // 配置管理
        // =============================

        /// <summary>
        /// 创建通知配置
        /// </summary>
        Task<TenantNotificationConfig> CreateConfigAsync(string tenantId, string notificationType, string channel, Dictionary<string, object> configuration);

        /// <summary>
        /// 更新通知配置
        /// </summary>
        Task<TenantNotificationConfig?> UpdateConfigAsync(long configId, bool? isEnabled = null, Dictionary<string, object>? configuration = null);

        /// <summary>
        /// 获取通知配置
        /// </summary>
        Task<List<TenantNotificationConfig>> GetConfigsAsync(string tenantId, string? notificationType = null);

        /// <summary>
        /// 删除通知配置
        /// </summary>
        Task<bool> DeleteConfigAsync(long configId);

        // =============================
        // 订阅管理
        // =============================

        /// <summary>
        /// 创建通知订阅
        /// </summary>
        Task<NotificationSubscription> CreateSubscriptionAsync(string tenantId, string userId, string eventType, string notificationType, string frequency = "immediate");

        /// <summary>
        /// 更新通知订阅
        /// </summary>
        Task<NotificationSubscription?> UpdateSubscriptionAsync(long subscriptionId, bool? isEnabled = null, string? frequency = null);

        /// <summary>
        /// 获取用户订阅
        /// </summary>
        Task<List<NotificationSubscription>> GetUserSubscriptionsAsync(string tenantId, string userId);

        /// <summary>
        /// 删除通知订阅
        /// </summary>
        Task<bool> DeleteSubscriptionAsync(long subscriptionId);

        // =============================
        // 记录查询
        // =============================

        /// <summary>
        /// 获取通知记录
        /// </summary>
        Task<List<NotificationRecord>> GetNotificationRecordsAsync(string tenantId, string? status = null, DateTime? startDate = null, DateTime? endDate = null, int page = 1, int pageSize = 20);

        /// <summary>
        /// 获取通知统计
        /// </summary>
        Task<Dictionary<string, long>> GetNotificationStatisticsAsync(string tenantId, DateTime? startDate = null, DateTime? endDate = null);

        /// <summary>
        /// 重试失败的通知
        /// </summary>
        Task<bool> RetryNotificationAsync(long recordId);

        /// <summary>
        /// 取消计划的通知
        /// </summary>
        Task<bool> CancelScheduledNotificationAsync(long recordId);
    }
}
